package edu.henu.personnel.dao;

import edu.henu.personnel.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: PersonnelProject
 * @description: user用户的sql操作
 * @author: zhuyang
 */

//@Mapper
@Repository
public interface UserDao {

    @Select("select * from t_user")
    List<User> findAllUser();

    /**
     * 获取管理用户的全部信息
     * @param uid
     * @return  返回管理用户的全部信息
     */
    @Select("select * from t_user where uid=#{uid}")
    User getUserInfoById(@Param("uid") String uid);

    /**
     * 根据用户的工号和密码获取用户信息并且进行登录操作
     * @param uid
     * @param upwd
     * @return
     */
    @Select("select * from t_user where uid=#{uid} and upwd=#{upwd}")
    User getUserInfoByCond(@Param("uid") String uid, @Param("upwd") String upwd);


    // 修改用户密码
    @Update("update t_user set upwd=#{upwd} where uid=#{uid}")
    int updateUserPwd(User user);

    /**
     * 更改管理用户信息
     * @param user
     * @return 更改是否成功返回1，否则返回0
     */
    @Update("update t_user set upwd=#{upwd}," +
            "utype=#{utype}," +
            "udept=#{udept}," +
            "uphone=#{uphone}," +
            "ustatus=#{ustatus}," +
            "umemo=#{umemo}" +
            "where uid=#{uid}"
    )
    int updateUserInfo(User user);

    /**
     * 添加管理用户
     * @param user
     * @return 插入成功返回1，否则返回0
     */
    @Insert("insert into t_user(uid, upwd, utype, udept, uphone, ustatus, umemo) values" +
            "(#{uid}, #{upwd}, #{utype}, #{udept}, #{uphone}, #{ustatus}, #{umemo})")
    int insertUser(User user);

    /**
     * 删除管理用户
     * @param uid 主键
     * @return 删除成功返回1，否则返回0
     */
    @Delete("delete from t_user where uid = #{uid}")
    int deleteUserById(String uid);
}
